﻿
using HBase;
using hcollection;
using MongoDB.Bson;
using System;
using System.Collections.Generic;
namespace hconnect {
    public abstract class Synchro :ZtTask {
        protected abstract AbsStatus parse();

        public override bool excute() {
            AbsStatus cs = parse();
            if( cs == null ) {
                return false;
            }

            syncDb(cs);

            StatusCache.setStatus(GetType() ,cs);
            BsonDocument document = BsonDocument.Parse(JsonUtil.mySerializeObject(cs));
            BsonDocument his = StatusCache.getHis(GetType());
            if( his != null ) {

                String date = his["time"].AsString.Substring(14 ,2);

                if( int.Parse(date) != cs.time.Minute ) {
                    his = null;
                }
            }

            List<BsonDocument> defList = cs.getDef(his ,document);
            cs.publish(defList);
            StatusCache.addDef(defList);
            StatusCache.setHis(GetType() ,document);
            return true;
        }
        protected abstract void syncDb(AbsStatus cs);

    }
}
